{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "87ad4531",
   "metadata": {
    "pycharm": {
     "is_executing": true,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "#导入相关库\n",
    "import pandas as pd\n",
    "import sqlalchemy\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Line, Bar\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86549490",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "#获取数据\n",
    "def read_data(table):\n",
    "    sql = \"SELECT * FROM \" + table\n",
    "    # 设置openGauss数据库版本信息\n",
    "    from sqlalchemy.dialects.postgresql.base import PGDialect\n",
    "    PGDialect._get_server_version_info = lambda *args: (9, 2)\n",
    "    userName = 'myroot'\n",
    "    password = 'myroot_123'\n",
    "    dbHost = '10.10.74.207'\n",
    "    dbPort = 15400\n",
    "    dbName = 'app'\n",
    "    DB_CONNECT = f'postgresql://{userName}:{password}@{dbHost}:{dbPort}/{dbName}'\n",
    "    conn_new = sqlalchemy.create_engine(DB_CONNECT)\n",
    "    if conn_new:\n",
    "        print(\"连接数据库成功\")\n",
    "    df = pd.read_sql(sql, conn_new)\n",
    "    print(df.columns)\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1b6e44b1",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "连接数据库成功\n",
      "Index(['id', 'selfid', 'name', 'addr'], dtype='object')\n",
      "连接数据库成功\n",
      "Index(['id', 'companyid', 'name', 'equipmentnumber'], dtype='object')\n",
      "连接数据库成功\n",
      "Index(['id', 'datetime', 'equipmentnumber', 'worktime', 'standbytime'], dtype='object')\n"
     ]
    }
   ],
   "source": [
    "# 读取公司信息CompanyInfos，设备信息InstallInfos，运行时间信息TimeInfos，删除id列\n",
    "CompanyInfos = read_data('companyinfos')\n",
    "CompanyInfos.drop(columns='id', inplace=True)\n",
    "InstallInfos = read_data('installinfos')\n",
    "InstallInfos.drop(columns='id', inplace=True)\n",
    "TimeInfos = read_data('timeinfos')\n",
    "TimeInfos.drop(columns='id', inplace=True)\n",
    "# 将表中的数据'worktime','standbytime'转换成浮点数\n",
    "TimeInfos['worktime'] = TimeInfos['worktime'].astype('float64')\n",
    "TimeInfos['standbytime'] = TimeInfos['standbytime'].astype('float64')\n",
    "# 计算所需的 每天停机时间:'stoptime',开机率'startrate',工作效率:'efficiency'\n",
    "TimeInfos['stoptime'] = round(24 - (TimeInfos['worktime'] + TimeInfos['standbytime']), 2)\n",
    "TimeInfos['startrate'] = round(((TimeInfos['worktime'] + TimeInfos['standbytime']) / 24) * 100, 2)\n",
    "TimeInfos['efficiency'] = round(TimeInfos['worktime'] / (TimeInfos['worktime'] + TimeInfos['standbytime']) * 100, 2)\n",
    "TimeInfos.fillna(0, inplace=True)\n",
    "# 获取TimeInfos表中的最大日期，并筛选出该日期对应的数据保存在day_timeinfos变量中\n",
    "date = TimeInfos['datetime'].max()\n",
    "day_timeinfos = TimeInfos[TimeInfos['datetime'] == date]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b730a22d",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 所有设备工作时间统计\n",
    "workTime_mean = round(day_timeinfos['worktime'].mean(), 2)\n",
    "higher = 0; lower = 0; count = 0\n",
    "for i in day_timeinfos['worktime']:\n",
    "    if i < workTime_mean:\n",
    "        lower += 1\n",
    "    else:\n",
    "        higher += 1\n",
    "    count += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "664872aa",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"627797b31c2f4cea8da94e262aec9f01\" style=\"width:100%; height:420px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_627797b31c2f4cea8da94e262aec9f01 = echarts.init(\n",
       "                    document.getElementById('627797b31c2f4cea8da94e262aec9f01'), 'white', {renderer: 'canvas'});\n",
       "                var option_627797b31c2f4cea8da94e262aec9f01 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u603b\\u8bbe\\u5907\\u6570\\u91cf\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                66,\n",
       "                0\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": 5,\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"itemStyle\": {\n",
       "                \"color\": \"#33ffff\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u4f4e\\u4e8e\\u5e73\\u5747\\u5de5\\u4f5c\\u65f6\\u957f\\u8bbe\\u5907\\u6570\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                0,\n",
       "                40\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": 5,\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"itemStyle\": {\n",
       "                \"color\": \"#9999ff\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u9ad8\\u4e8e\\u5e73\\u5747\\u5de5\\u4f5c\\u65f6\\u957f\\u8bbe\\u5907\\u6570\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                0,\n",
       "                0,\n",
       "                26\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": 5,\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"itemStyle\": {\n",
       "                \"color\": \"#33ff99\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u603b\\u8bbe\\u5907\\u6570\\u91cf\",\n",
       "                \"\\u4f4e\\u4e8e\\u5e73\\u5747\\u5de5\\u4f5c\\u65f6\\u957f\\u8bbe\\u5907\\u6570\",\n",
       "                \"\\u9ad8\\u4e8e\\u5e73\\u5747\\u5de5\\u4f5c\\u65f6\\u957f\\u8bbe\\u5907\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u603b\\u8bbe\\u5907\\u6570\\u91cf\": true,\n",
       "                \"\\u4f4e\\u4e8e\\u5e73\\u5747\\u5de5\\u4f5c\\u65f6\\u957f\\u8bbe\\u5907\\u6570\": true,\n",
       "                \"\\u9ad8\\u4e8e\\u5e73\\u5747\\u5de5\\u4f5c\\u65f6\\u957f\\u8bbe\\u5907\\u6570\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"right\": \"5\",\n",
       "            \"top\": \"20\",\n",
       "            \"orient\": \"vertical\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 5,\n",
       "            \"itemHeight\": 14,\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"black\",\n",
       "                \"fontSize\": 10\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"\\u603b\",\n",
       "                \"\\u4f4e\",\n",
       "                \"\\u9ad8\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u8bbe\\u5907\\u5de5\\u4f5c\\u6548\\u7387\\u7edf\\u8ba1\\uff08\\u8bbe\\u5907\\u6570\\u7edf\\u8ba1\\uff09\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"black\"\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_627797b31c2f4cea8da94e262aec9f01.setOption(option_627797b31c2f4cea8da94e262aec9f01);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f65a8e5c668>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar = Bar(init_opts=opts.InitOpts(width='100%', height='420px'))\n",
    "bar.add_xaxis(xaxis_data=['总', '低', '高'])\n",
    "bar.add_yaxis(\"总设备数量\", y_axis=[count, 0, ], category_gap=5, itemstyle_opts=opts.ItemStyleOpts(color='#33ffff'))\n",
    "bar.add_yaxis(\"低于平均工作时长设备数\", y_axis=[0, lower, ], category_gap=5, itemstyle_opts=opts.ItemStyleOpts(color='#9999ff'))\n",
    "bar.add_yaxis(\"高于平均工作时长设备数\", y_axis=[0, 0, higher], category_gap=5, itemstyle_opts=opts.ItemStyleOpts(color='#33ff99'))\n",
    "bar.set_global_opts(title_opts=opts.TitleOpts('设备工作效率统计（设备数统计）', title_textstyle_opts={\"color\": \"black\"}),\n",
    "    legend_opts=opts.LegendOpts(\n",
    "    is_show=True, pos_right='5', pos_top='20', orient='vertical', item_width=5,\n",
    "    textstyle_opts=opts.TextStyleOpts(font_size=10, color=\"black\")\n",
    "),\n",
    "    xaxis_opts=opts.AxisOpts(\n",
    "        axislabel_opts=opts.LabelOpts(color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    ),\n",
    "    yaxis_opts=opts.AxisOpts(\n",
    "        axislabel_opts=opts.LabelOpts(color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    )\n",
    ")\n",
    "bar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))\n",
    "bar.reversal_axis()\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b8e6d9ac",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"568a3780361149aaa5f716b7b316f75e\" style=\"width:100%; height:420px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_568a3780361149aaa5f716b7b316f75e = echarts.init(\n",
       "                    document.getElementById('568a3780361149aaa5f716b7b316f75e'), 'white', {renderer: 'canvas'});\n",
       "                var option_568a3780361149aaa5f716b7b316f75e = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#33ffff\",\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                24.0,\n",
       "                13.41,\n",
       "                9.59,\n",
       "                9.51,\n",
       "                9.5,\n",
       "                9.48,\n",
       "                8.7,\n",
       "                8.54,\n",
       "                8.23,\n",
       "                8.0\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": 10,\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"color\": \"white\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"rotate\": 15,\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"DNKLY4033064-A\",\n",
       "                \"DNKLY4032435-A\",\n",
       "                \"DNKLY4032495-A\",\n",
       "                \"DNKLY4036450-A\",\n",
       "                \"DNKLY4036456-A\",\n",
       "                \"DNKLY4036455-A\",\n",
       "                \"DNKLY4032487-A\",\n",
       "                \"DNKLY4032185-A\",\n",
       "                \"DNKLY4033100-A\",\n",
       "                \"DNKLY4033029-A\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u65f6\\u957f\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"max\": 24,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u8bbe\\u5907\\u5de5\\u4f5c\\u65f6\\u957f\\u524d\\u5341\\u540d\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"black\"\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_568a3780361149aaa5f716b7b316f75e.setOption(option_568a3780361149aaa5f716b7b316f75e);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f65626ceda0>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设备工作时长前十名\n",
    "top = day_timeinfos.sort_values(by='worktime', ascending=False).head(10)\n",
    "equipMentNumber_list = top['equipmentnumber'].tolist()\n",
    "workTime_list = top['worktime'].tolist()\n",
    "bar = Bar(init_opts=opts.InitOpts(width='100%', height='420px'))\n",
    "bar.add_xaxis(equipMentNumber_list)\n",
    "bar.add_yaxis(\"\", workTime_list, color='#33ffff', category_gap=10)\n",
    "bar.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(title='设备工作时长前十名', title_textstyle_opts={\"color\": \"black\"}),\n",
    "    yaxis_opts=opts.AxisOpts(\n",
    "        max_=24, name='时长', axislabel_opts=opts.LabelOpts(color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    ),\n",
    "    xaxis_opts=opts.AxisOpts(\n",
    "        axislabel_opts=opts.LabelOpts(rotate=15, color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    )\n",
    ")\n",
    "bar.set_series_opts(label_opts={\"color\": \"white\"})\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "355349b4",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 所有设备的平均开机率（七天）\n",
    "# 聚合求平均值匹配\n",
    "TimeInfos_mean = round(TimeInfos.groupby(by='datetime', sort=True, as_index=False).agg({'startrate': 'mean'}),2)\n",
    "date = (datetime.datetime.strptime(TimeInfos['datetime'].max(), '%Y-%m-%d') + datetime.timedelta(days=-7)).strftime('%Y-%m-%d')\n",
    "timeinfo = TimeInfos_mean[TimeInfos_mean['datetime'] >= date]\n",
    "date_list = timeinfo['datetime'].tolist()\n",
    "startRate_list = timeinfo['startrate'].tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "56321b7e",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"458cc89972a646af8011220606d52ad5\" style=\"width:100%; height:420px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_458cc89972a646af8011220606d52ad5 = echarts.init(\n",
       "                    document.getElementById('458cc89972a646af8011220606d52ad5'), 'white', {renderer: 'canvas'});\n",
       "                var option_458cc89972a646af8011220606d52ad5 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#33ffff\",\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"12-16\",\n",
       "                    46.85\n",
       "                ],\n",
       "                [\n",
       "                    \"12-18\",\n",
       "                    47.08\n",
       "                ],\n",
       "                [\n",
       "                    \"12-19\",\n",
       "                    48.4\n",
       "                ],\n",
       "                [\n",
       "                    \"12-21\",\n",
       "                    51.01\n",
       "                ],\n",
       "                [\n",
       "                    \"12-22\",\n",
       "                    44.1\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"white\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0,\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"12-16\",\n",
       "                \"12-18\",\n",
       "                \"12-19\",\n",
       "                \"12-21\",\n",
       "                \"12-22\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"name\": \"\\u5f00\\u673a\\u7387(%)\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6240\\u6709\\u8bbe\\u5907\\u7684\\u5e73\\u5747\\u5f00\\u673a\\u7387\\uff08\\u4e03\\u5929\\uff09\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"black\"\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_458cc89972a646af8011220606d52ad5.setOption(option_458cc89972a646af8011220606d52ad5);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f6560c001d0>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line = Line(init_opts=opts.InitOpts(width='100%', height='420px'))\n",
    "line.add_xaxis([i[5:] for i in date_list])  # 切取时间\n",
    "line.add_yaxis(\"\", startRate_list, color='#33ffff')\n",
    "line.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(\n",
    "        title='所有设备的平均开机率（七天）', title_textstyle_opts={\"color\": \"black\"}\n",
    "    ),  # 主标题\n",
    "    yaxis_opts=opts.AxisOpts(\n",
    "        name=\"开机率(%)\", axislabel_opts=opts.LabelOpts(color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    ),  # Y轴的设置\n",
    "    xaxis_opts=opts.AxisOpts(\n",
    "        axislabel_opts=opts.LabelOpts(color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    )  #X轴的设置\n",
    ")\n",
    "line.set_series_opts(label_opts=opts.LabelOpts(color='white'))\n",
    "line.render_notebook()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
